Hi Harrison, I've been following along with your python/pygame tutorials you did for the newboston. I was doing ok'ish up to around video 67, when python keeps giving me the following error.. ZeroDivisionError:float division by zero. At which point everything just 'stops'.
The line of code that seems to be causing the problem is line 356.. " startingShell[1] += int((((startingShell[0]-xy[0]*0.015/currentPower/50))**2)-(turPos+turPos/(12-turPos))) "
Being very new to python/ pygame and programming in general it has left me kind of frustrated as like I said all was going OK'ish to this point. This happens if I have manually added the code myself as i follow along or even if i copy/paste from the source code 'Bucky' put on his forum.
many thanks
Chris..
You must be logged in to post. Please login or register an account.
ZeroDivisionError is going to occur any time you try to divide anything by zero. This is a mathematical principle. Either currentPower/50 = 0 (nope), or 12-turPos = 0.
Now, in Python 3, this doesn't happen, so I am going to assume you are using Python 2, which is probably where the real problem is occurring, I would wager its the currentPower/50 part.
Python 2 doesn't divide into floats like Python 3 does naturally.
If you are using Python 2, update to Python 3. If you refuse, do:
from __future__ import division
-Harrison 9 years ago
You must be logged in to post. Please login or register an account.
Hi Harrison,
from __future__ import division worked a treat.
I am using python 2.7 on a linux PC, with 'spyder' as the IDE. I also have Python 3.5 as well, but, 'spyder' doesn't seem to want to use it, more fussy than I am I guess. I'll get round to sorting things out, it's all happened because I killed Win7 a few weeks ago. So I was looking for an OS and found 'linux'. Thanks for the quick answer.
Chris..
-chris1961 9 years ago
You must be logged in to post. Please login or register an account.